<?php
// +----------------------------------------------------------------------
// | Quotes [ 只为给用户更好的体验]**[我知道发出来有人会盗用,但请您留版权]
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 零度  <2109877665@qq.com>          盗用不留版权,你就不配拿去!
// +----------------------------------------------------------------------
// | Date: 2019年08月20日
// +----------------------------------------------------------------------

/**
 * 授权管理
**/
$title='授权管理';
include './Head.php';

//$authcode=md5(mt_rand(1000000000,9999999999).$qq);
?>

<?php
$my=isset($_GET['my'])?$_GET['my']:null;
if($my=='add')
{
?>
<div class="block">
<div class="panel-heading"><h3 class="panel-title">添加授权</h3></div>
<div class="panel-body">
<div class="form-group">
<div class="form-group">
<label>授权域名:</label><br>
<input type="text" class="form-control" name="url" id="url" value="" placeholder="不用带http;//...//">
</div>
<div class="form-group">
<label>授权QQ:</label><br>
<input class="form-control" name="qq" id="qq" value="" placeholder="不可留空">
</div>
<div class="form-group">
<label>备注:</label><br>
<input class="form-control" name="beizhu" id="beizhu" value="" placeholder="可留空">
</div>
<button type="sumbit" class="btn btn-primary btn-block" onclick="add_user();">确定添加</button>
<br/><a href="./">>>返回列表</a>
<?php 
}
elseif($my=='edit')
{
$id=$_GET['id'];
$row=$DB->query("select * from pay_check where id='$id' limit 1")->fetch();
?>
<div class="block">
<div class="panel-heading"><h3 class="panel-title">修改授权</h3></div>
<div class="panel-body">
<input type="hidden" name="id" id="id" value="<?=$row['id']?>"/>
<div class="form-group">
<label>授权域名:</label><br>
<input type="text" class="form-control" name="url" id="url" value="<?=$row['url']?>" placeholder="不用带http;//...//">
</div>
<div class="form-group">
<label>授权QQ:</label><br>
<input class="form-control" name="qq" id="qq" value="<?=$row['qq']?>" placeholder="不可留空">
</div>
<div class="form-group">
<label>备注:</label><br>
<input class="form-control" name="beizhu" id="beizhu" value="<?=$row['beizhu']?>" placeholder="">
</div>
<button type="sumbit" class="btn btn-primary btn-block" onclick="edit_user();">确定修改</button>
<br/><a href="./">>>返回列表</a>
</div>
<?php
}
else
{

echo '
<div class="block">
        <div class="panel-heading"><h3 class="panel-title">操作中心</h3></div>
		<div class="panel-body"><form action="" method="GET" class="form-inline"><input type="hidden" name="my" value="search">
  <div class="form-group">
    <label>条件搜索</label>
	<select name="column" class="form-control"><option value="qq">授权QQ</option><option value="url">授权域名</option></select>
  </div>
  <div class="form-group">
    <input type="text" class="form-control" name="value" placeholder="搜索内容">
  </div>
  <button type="submit" class="btn btn-primary">搜索</button> <a href="?my=add" class="btn btn-primary">添加授权</a>
</form>';

if($my=='search'||$_GET['value']) {
	$sql=" `{$_GET['column']}`='{$_GET['value']}'";
	$numrows=$DB->query("SELECT * from pay_check WHERE{$sql}")->rowCount();
	$con='包含 '.$_GET['value'].' 的共有 <b>'.$numrows.'</b> 个授权';
}else{
	$numrows=$DB->query("SELECT * from pay_check WHERE 1")->rowCount();
	$sql=" 1";
	$con='系统共有 <b>'.$numrows.'</b> 个授权';
}
echo '<br>'.$con;
?>
</div>
  </div>
<div class="block">
          <tbody>
		  <form name="form1" id="form1">
	  <div class="table-responsive">
        <table class="table table-striped table-bordered table-vcenter">
		<thead>
												<tr><th>授权商</th><th>授权域名</th><th>QQ号</th><th>备注</th><th>云端账号</th><th>云端密码</th><th>状态</th><th>添加时间</th><th>操作</th></tr></thead>
          <tbody>
<?php
$pagesize=30;
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
{
 $pages++;
 }
if (isset($_GET['page'])){
$page=intval($_GET['page']);
}
else{
$page=1;
}
$offset=$pagesize*($page - 1);

$rs=$DB->query("SELECT * FROM pay_check WHERE{$sql} order by addtime desc limit $offset,$pagesize");
while($res = $rs->fetch())
{
$cloud=$DB->query("SELECT * FROM `pay_cloud` WHERE `qq`='{$res['qq']}' limit 1")->fetch();
echo '<tr>
<td><b>'.$res['daili_id'].'</b></td>
<td><b>'.$res['url'].'</b></td>
<td><b>'.$res['qq'].'</b></td>
<td><b>'.$res['beizhu'].'</b></td>
<td><b>'.$cloud['pid'].'</b></td>
<td><b>'.$cloud['key'].'</b></td>
<td><b>'.status_zt($res['status']).'</b></td>
<td><b>'.$res['addtime'].'</b></td>
<td><a href="Downfile.php?qq='.$res['qq'].'" class="btn btn-xs btn-success">下载源码</a>&nbsp;<a href="?my=edit&id='.$res['id'].'" class="btn btn-xs btn-primary">编辑</a>&nbsp;<a onclick="status_user('.$res['id'].');" class="btn btn-xs btn-info">禁封/解除</a></td>
</tr>';
}
?>
          </tbody>
        </table>
      </div>
<?php
echo'<ul class="pagination">';
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if ($page>1)
{
echo '<li><a href="?page='.$first.$link.'">首页</a></li>';
echo '<li><a href="?page='.$prev.$link.'">&laquo;</a></li>';
} else {
echo '<li class="disabled"><a>首页</a></li>';
echo '<li class="disabled"><a>&laquo;</a></li>';
}
for ($i=1;$i<$page;$i++)
echo '<li><a href="?page='.$i.$link.'">'.$i .'</a></li>';
echo '<li class="disabled"><a>'.$page.'</a></li>';
for ($i=$page+1;$i<=$pages;$i++)
echo '<li><a href="?page='.$i.$link.'">'.$i .'</a></li>';
echo '';
if ($page<$pages)
{
echo '<li><a href="?page='.$next.$link.'">&raquo;</a></li>';
echo '<li><a href="?page='.$last.$link.'">尾页</a></li>';
} else {
echo '<li class="disabled"><a>&raquo;</a></li>';
echo '<li class="disabled"><a>尾页</a></li>';
}
echo'</ul>';
#分页
}
?>
    </div>
  </div>
  
  <script type="text/javascript">
  function status_user(id){//删除用户
		if(id==''){layer.alert('请确保各项不能为空！');return false;}
		  	var ii = layer.load(3, {shade:[0.1,'#fff']});
		  	$.ajax({
				type : "POST",
				url : "Ajax.php?act=Status_check",
				data : {id},
				dataType : 'json',
				timeout:10000,
				success : function(data) {					  
					  layer.close(ii);
					  layer.msg(data.msg);
					  if(data.code==1){
						setTimeout(function () {
							location.href="./Check.php";
						}, 1000); //延时1秒跳转
					  }
				},
				error:function(data){
					layer.close(ii);
					layer.msg('服务器错误');
					}
			});
		  	
}
  function add_user(){//添加用户
        var url= $("#url").val(); 
        var qq= $("#qq").val(); 
        var money= $("#money").val(); 
        var beizhu= $("#beizhu").val(); 
		if(url==''){layer.alert('必填项不能为空！');return false;}
		  	var ii = layer.load(3, {shade:[0.1,'#fff']});
		  	$.ajax({
				type : "POST",
				url : "Ajax.php?act=Add_check",
				data : {url,qq,money,beizhu},
				dataType : 'json',
				timeout:10000,
				success : function(data) {					  
					  layer.close(ii);
					  layer.msg(data.msg);
					  if(data.code==1){
						setTimeout(function () {
							location.href="./Check.php";
						}, 1000); //延时1秒跳转
					  }
				},
				error:function(data){
					layer.close(ii);
					layer.msg('服务器错误');
					}
			});
		  	
}
  function edit_user(){//修改用户
        var id= $("#id").val(); 
        var url= $("#url").val(); 
        var qq= $("#qq").val(); 
        var money= $("#money").val(); 
        var beizhu= $("#beizhu").val(); 
		if(id==''){layer.alert('必填项不能为空！');return false;}
		  	var ii = layer.load(3, {shade:[0.1,'#fff']});
		  	$.ajax({
				type : "POST",
				url : "Ajax.php?act=Edit_check",
				data : {id,url,qq,money,beizhu},
				dataType : 'json',
				timeout:10000,
				success : function(data) {					  
					  layer.close(ii);
					  layer.msg(data.msg);
					  if(data.code==1){
						setTimeout(function () {
							location.href="./Check.php";
						}, 1000); //延时1秒跳转
					  }
				},
				error:function(data){
					layer.close(ii);
					layer.msg('服务器错误');
					}
			});
		  	
}
  </script>